<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class JudgeDocument extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->library('HttpPost');
		$this->load->model('Court_Model');
		$this->load->helper('url_helper');
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 *        http://example.com/index.php/welcome
	 *    - or -
	 *        http://example.com/index.php/welcome/index
	 *    - or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */


	public function judge_doc_list()
	{
		$data['ah']='';
		$data['cbfy']='';
		if(isset($_POST['pageno'])){
			$data['pageno']=$_POST['pageno'];
		}else{
			$data['pageno']=1;
		}
		if(isset($_POST['pagesize'])){
			$data['pagesize']=$_POST['pagesize'];
		}else{
			$data['pagesize']=15;
		}
		if(isset($_POST['ajlb'])){
			$data['ajlb']=$_POST['ajlb'];
		}
		if(isset($_POST['cbfy'])){
			$data['cbfy']=$_POST['cbfy'];
		}else{
			$data['cbfy']='1304';
		}
		if(isset($_POST['ah'])){
			$data['ah']=$_POST['ah'];
		}
		if(isset($_POST['jarq1'])){
			$data['jarq1']=$_POST['jarq1'];
		}else{
			$data['jarq1']='20060101';
		}
		if(isset($_POST['jarq2']) && !empty($_POST['jarq2'])){
			$data['jarq2']=$_POST['jarq2'];
		}else{
			$cur_date=date("Ymd" ,time());
			$data['jarq2']=$cur_date;
		}
		if(isset($_POST['key'])){
			$data['key']=$_POST['key'];
		}
		$url='http://www.zjsfgkw.cn/document/JudgmentSearch';
		$timeout = 40;
		$response=$this->httppost->post($url,$data,$timeout);
		$courts=array();
		if (!($this->input->post("isAjax"))) {
			$courts=$this->Court_Model-> get_all_courts();
		}
		$sdlist=json_decode($response);
//		print_r($sdlist);
	//	print_r($sdlist->list);
		$searchsel['ah']=$data['ah'];
		$searchsel['cbfy']=$data['cbfy'];
		$articles=array('title'=>'裁判文书');
		$articles['searchsel']=$searchsel;
		$articles['courts'] = $courts;
		$articles['judgedocs']=$sdlist;
		if(empty($this->input->post("isAjax"))){
			$this->load->view('head_sec',$articles);
			$this->load->view('judge_doc_list',$articles);
			$this->load->view('foot_sec',$articles);
		}else{
			header('content-type:application:json;charset=utf8');
			header('Access-Control-Allow-Origin:*');
			header('Access-Control-Allow-Methods:POST');
			header('Access-Control-Allow-Headers:x-requested-with,content-type');
			$result = array();
			$result['isSuccess'] = true;
			$result['errorMessage'] = '';
			$result['data'] = $sdlist;
			echo json_encode($result, JSON_UNESCAPED_UNICODE);
		}

	}
//	提供给ajax方法调用
	public function ajax_sd_list($p=1,$cbfy='')
	{
		print_r($cbfy);
		$data=array();
		$data['pageno'] = $p;
		$data['pagesize'] = 10;
		$data['cbfy'] = $cbfy;
		$url='http://www.zjsfgkw.cn/Notice/NoticeSD';
		$timeout = 40;
		$response=$this->httppost->post($url,$data,$timeout);
		$sdlist=json_decode($response);

		//print_r($sdlist[1]['total']);

		$articles=array('t=itle'=>'送达公告');
		$articles['court_announces']=$sdlist;
		$this->load->view('head_sec',$articles);
		$this->load->view('sd_announce_list',$articles);
		$this->load->view('foot_sec',$articles);
	}
	public function detail($id){
		$url_prefix="http://www.zjsfgkw.cn/document/JudgmentDetail/";
		$url=$url_prefix.$id;
		$content=$this->httppost->get_url_html($url);
		$reg_tag_a = '/<IFRAME+\s+.+src=\"([^\"]*?)\"/';
		$attach_url=$this->httppost->filter_url($content,$reg_tag_a);

		$attach="http://www.zjsfgkw.cn".$attach_url[0];
		$title='文书详情';
		$data=array('title'=>$title,
			'attach'=>$attach
		);
		$this->load->view('head_sec',$data);
		$this->load->view('judge_doc_detail',$data);
		$this->load->view('foot_sec',$data);
	}
}


